package poiSeleniumTests;

import com.thoughtworks.selenium.*;
import poi.POIDatabase;

public class EditSeleniumTest extends SeleneseTestCase {
	public void setUp() throws Exception {
		setUp("http://localhost:8080/POISystem/", "*chrome");
	}
	public void testPOIEditor() throws Exception {
		selenium.open("/POISystem/");
		selenium.click("link=Add new POI");
		selenium.waitForPageToLoad("30000");
		selenium.type("j_id_jsp_2072368545_1:j_id_jsp_2072368545_7", "Test");
		selenium.select("j_id_jsp_2072368545_1:poiType", "label=Recreation");
		selenium.type("j_id_jsp_2072368545_1:j_id_jsp_2072368545_15", "1");
		selenium.type("j_id_jsp_2072368545_1:j_id_jsp_2072368545_17", "2");
		int id = Integer.parseInt(selenium.getValue("j_id_jsp_2072368545_1:j_id_jsp_2072368545_5"));
		selenium.click("j_id_jsp_2072368545_1:j_id_jsp_2072368545_18");
		selenium.waitForPageToLoad("30000");
		
		selenium.open("/POISystem/");
		selenium.click("link=Edit existing POI");
		selenium.waitForPageToLoad("30000");
		selenium.click("//form[@id='j_id_jsp_460134654_1']/table/tbody/tr[8]/td[3]/a");
		selenium.waitForPageToLoad("30000");
		selenium.type("j_id_jsp_2072368545_1:j_id_jsp_2072368545_7", "Aqua_new");
		selenium.click("j_id_jsp_2072368545_1:j_id_jsp_2072368545_18");
		selenium.waitForPageToLoad("30000");

		selenium.open("/POISystem/");
		selenium.click("link=Edit existing POI");
		selenium.waitForPageToLoad("30000");
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>7</td>"),-1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Aqua_new</td>"),-1);
		String s = ((Integer) id).toString();
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>"+s+"</td>"),-1);
		assertNotEquals(selenium.getHtmlSource().indexOf("<td>Test</td>"),-1);

		selenium.open("/POISystem/");
		selenium.click("link=Edit existing POI");
		selenium.waitForPageToLoad("30000");
		selenium.click("//form[@id='j_id_jsp_460134654_1']/table/tbody/tr[8]/td[3]/a");
		selenium.waitForPageToLoad("30000");
		selenium.type("j_id_jsp_2072368545_1:j_id_jsp_2072368545_7", "Aqua");
		selenium.click("j_id_jsp_2072368545_1:j_id_jsp_2072368545_18");
		selenium.waitForPageToLoad("30000");
		POIDatabase db = new POIDatabase();
		db.connectSource(null);
		assertTrue(db.deleteRecord(id));
	}
}